<?php
//App::import('Vendor','tcpdf/tcpdf');
App::import('Vendor','xtcpdf');
$tcpdf = new XTCPDF();
//$tcpdf = new XTCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$textfont = 'helvetica';
 
//$tcpdf->SetAuthor("bachpt");
//$tcpdf->SetAutoPageBreak(true);

$tcpdf->setHeaderFont(array($textfont,'',20)); 
$tcpdf->xheadercolor = array(150,0,0); 
$tcpdf->xheadertext = '# Messages Per School'; 
$tcpdf->xfootertext = 'Beaconschool. All rights reserved.'; 
 
$tcpdf->setPrintHeader(true);
$tcpdf->setPrintFooter(true);

// set default monospaced font
$tcpdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$tcpdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
//$tcpdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$tcpdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$tcpdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$tcpdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

$tcpdf->SetTextColor(0, 0, 0);
$tcpdf->SetFont($textfont,'',7);
 
$tcpdf->AddPage();


 
// create some HTML content


$htmlcontent = '<table border="0" style="width: 100%">
					<tr>
						<td  style="width: 25%;text-align:left" ><b>School</b></td>
						<td style="width: 25%;text-align:center"><b>Contact</b></td>
						<td  style="width: 25%;text-align:center"><b>Sponsor</b></td>
						<td  style="width: 25%;text-align:right"><b>Messages sent</b></td>
					</tr>
			</table>';
			
$tcpdf->writeHTML($htmlcontent, true, 0, true, 0);
		
foreach ($schools as $school) {
	$htmlcontent = "
		<table>
			<tr>
				<td style=\"width: 25%;text-align:left\">{$school['School']['schoolName']}</td>
				<td style=\"width: 25%;text-align:center\">{$school['Contact']['contactName']}</td>
				<td style=\"width: 25%;text-align:center\">{$school['Sponsor']['sponsorName']}</td>
				<td style=\"width: 135px;text-align:right\">{$school[0]['totalMessage']}</td>
			</tr>
		</table>
";
// output the HTML content
$tcpdf->writeHTML($htmlcontent, true, 0, true, 0);
$tcpdf->Cell(0, 0, '' ,'T', 1, 'L');
}

$tcpdf->Output('Messages_per_schools.pdf', 'D');
?>
